﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>方向条件-按照岗位计算</title>
    <!-- 于庆海 -->
    <script language="JavaScript" src="../Comm/JScript.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../Comm/Style/Table0.css" rel="stylesheet" type="text/css" />
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script src="../Comm/JScript.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");
        });
        //初始化数据.
        function InitPage() {

            var fk_node = GetQueryString("FK_Node");
            var param = location.href.split("?")[1];


            //初始化表格.
            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=CondByStation_Init&FK_Node=" + fk_node + "&m=" + Math.random() + "&" + param,
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }

                    data = JSON.parse(data);

                    var fk_CondStationTemplate = GetQueryString("FK_CondStationTemplate");
                    var currCondStation = null;

                    //生成岗位列表.
                    //bgein
                    var types = data.StationTypes;

                    var sts = data.Stations;
                    var cond = data.Cond[0].OperatorValue;
                    for (var i = 0, len = types.length; i < len; i++) {
                        var typeno = types[i].No;

                        var curstas = [];
                        var ids = "";
                        for (var j = 0, jlen = sts.length; j < jlen; j++) {
                            if (sts[j].FK_StationType == typeno) {
                                curstas.push(sts[j]);
                                ids += "CB_" + sts[j].No + ",";
                            }
                        }

                        var title = "<tr><td colspan='3' class='GroupTitle'><input id='CB_type_" + typeno + "' type='checkbox' name='CB_type_" + typeno + "' onclick=\"SetSelected(this,'" + ids + "')\"/><label>" + types[i].Name + "</label></td></tr>";
                        $("#t1").append(title);

                        for (var k = 0, klen = curstas.length; k < klen; k++) {
                            var td = "<td><input type='checkbox' id='emp_CB_" + curstas[k].No + "' name='emp_CB_" + curstas[k].No + "'/><label for='emp_CB_" + curstas[k].No + "'>" + curstas[k].Name + "</label></td>";
                            if (k % 3 == 0) {
                                $("#t1").append("<tr></tr>");
                            }
                            $("#t1 tr:last").append(td);
                        }
                    }

                    var emps = cond.split("@");
                    for (i = 0, len = emps.length; i < len; i++) {
                        if (emps[i] == "") continue;
                        document.getElementById("emp_CB_" + emps[i]).checked = true;
                    }
                    //TODO 条件参数
                    var atpara = data.Cond[0].AtPara;
                    if (atpara != "") {
                        var initDDL_SpecOperWay = atpara.split("@")[1].split("=")[1];
                        document.getElementById("initDDL_SpecOperWay").value = initDDL_SpecOperWay;
                        document.getElementById("DDL_SpecOperWay").value = initDDL_SpecOperWay;

                        var initTB_SpecOperPara = atpara.split("@")[2].split("=")[1];
                        document.getElementById("TB_SpecOperPara").value = initTB_SpecOperPara;
                        if (initDDL_SpecOperWay != 0) {
                            document.getElementById("TB_SpecOperPara").disabled = "";
                        }
                        document.getElementById("initTB_SpecOperPara").value = initTB_SpecOperPara; 
                        $("#span" + initDDL_SpecOperWay).css("display", "inline-block");
                        $("#span" + initDDL_SpecOperWay).siblings().css("display", "none");
                    }
                    //条件参数 end

                    //end

                    //调用公共类库的方法:执行批量主表赋值
                    if (currCondStation != null)
                        GenerFullAllCtrlsVal(currCondStation);
                }
            });
        }

        function Btn_Delete_Click() {

            if (window.confirm('您确定要删除吗？') == false)
                return;

            var param = location.href.split("?")[1];
            $.ajax({
                data:'',
                type: 'post',
                async: true,
                url: Handler + "?DoType=CondByStation_Delete&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random() + "&" + param,
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }

                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        //ajax 提交
        function Btn_Save_Click() {

            var param = location.href.split("?")[1];
            //var checkBoxIDs = GenerCheckIDs(); //获得所有的 checkBox ID传入到后台去,用于解决checkbox控件，在没有被选择的时候，没有值的问题。
            //获取所有选中的checkbox
            var emps = ",";
            $("input[type='checkbox']").each(function () {

                if (this.checked && this.name.indexOf("emp_CB_") == 0) {
                    emps += this.name.replace("emp_CB_","") + ",";
                }
            });

            var frmData = $("#cc").serialize();
            //alert(frmData);
            $.ajax({
                data: frmData,
                type: 'post',
                async: true,
                url: Handler + "?DoType=CondByStation_Save" + "&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random() + "&emps=" + emps + "&" + param,
                dataType: 'html',
                success: function (data) {
                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }
                    alert(data);
                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        function selChange() {
            //01.如果 文本框 有初始值就赋初值
            var idx = document.getElementById("DDL_SpecOperWay").value;
            var idxinit = document.getElementById("initDDL_SpecOperWay").value;
            if (idx == idxinit) {
                document.getElementById("TB_SpecOperPara").value = document.getElementById("initTB_SpecOperPara").value;
            }
            else {
                document.getElementById("TB_SpecOperPara").value = "";
            }

            //02.处理文本框样式
            if (idx == 0) {
                document.getElementById("TB_SpecOperPara").disabled = "disabled";
            } else {
                document.getElementById("TB_SpecOperPara").disabled = "";
            }
            //03.处理标签
            $("#span" + idx).css("display", "inline-block");
            $("#span" + idx).siblings().css("display", "none");
        }
    </script>

    <style type="text/css">
        ul .cond li
        {
            display: none;
            line-height: 50px;
        }
        
        ul .cond li .active
        {
            display: block;
        }
        
        select
        {
            display: inline-block;
            width: 200px;
        }
        
        .btn
        {
            display:inline-block;
            height:20px;
            background-color:#0099ff;
            text-decoration:none;
            color:#fff;
            padding:3px 15px;
            margin:10px 10px;
        }
        .lbls span
        {
            width:80px;
         }
    </style>
</head>
<body>
    <form action="/" method="post" id="cc">
    <div>
        <div style="max-height:600px;overflow:auto;">
            <table id="t1" class="Table" cellspacing="1" cellpadding="1" border="1" style="width: 100%">
            </table>
        </div>
        <br />
        
        <div>
            指定的操作员：<select id="DDL_SpecOperWay" name="DDL_SpecOperWay" onchange="selChange()">
                <option selected="selected" value="0">当前操作员</option>
                <option value="1">指定节点的操作员</option>
                <option value="2">指定表单字段作为操作员</option>
                <option value="3">指定操作员编号</option>
            </select>
            <input type="hidden" name="initDDL_SpecOperWay" id="initDDL_SpecOperWay" value=" " />
            <input type="hidden" name="initTB_SpecOperPara" id="initTB_SpecOperPara" value=" " />
            <br />
            <br />            
            <span class="lbls">
                <span id="span0">参数：</span>
                <span id="span1" style="display: none">节点编号：</span>
                <span id="span2" style="display: none">表单字段：</span>
                <span id="span3" style="display: none">操作员编号：</span>
            </span>
            <input id="TB_SpecOperPara" name="TB_SpecOperPara" type="text" disabled="disabled" style="width: 200px;" />&nbsp;&nbsp;多个值请用英文“逗号”来分隔。
            <br />
            <a class="btn" href="javascript:Btn_Save_Click();">保&nbsp;存</a>&nbsp;&nbsp; 
            <a class="btn" href="javascript:Btn_Delete_Click();">删&nbsp;除</a>
            
        </div>
    </div>
    </form>
</body>
</html>
